﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tomahawk.Runtime.Logic;
using System.Xml.Serialization;

namespace Archetypes.Logic
{
    /// <summary>
    /// When the match is initialized, the rest of the game object will be created
    /// </summary>
    public class Match : XObject
    {

        #region "Serializable properties"

        // These properties will be automatically readed from the xml archetype, if
        // one it's specified during the object instantiation

        [XmlElement("Duration")]
        public float Duration;

        #endregion

        Player player1;
        Player player2;
        Ball ball;
        Lazy lazy;

        protected override void OnInitialize()
        {
            base.OnInitialize();

            //
            // Creating objects from archetypes
            //

            //create a player, using the human player archetype
            player1 = (Player)XWorld.Instance.CreateObject(typeof(Player), this, "Player1", "Examples.Archetypes.Content\\HumanPlayer.xml");
            
            //create another player, this time using the ai player archetype
            player2 = (Player)XWorld.Instance.CreateObject(typeof(Player), this, "Player2", "Examples.Archetypes.Content\\AIPlayer.xml");

            //
            // Creating objects without archetypes
            //

            //create the ball, without using an archetype
            ball = (Ball)XWorld.Instance.CreateObject(typeof(Ball), this, "Ball" );

            //
            // Creaeting lazy objects
            //

            //To use Lazy Initialization, call CreateObject with "false" as the first argument
            lazy = (Lazy)XWorld.Instance.CreateObject(false, typeof(Lazy), this, "Lazy");
            
            //now set its properties
            lazy.DummyProperty1 = "asd";
            lazy.DummyProperty2 = 3.14f;
            
            //and now manually initialize it
            lazy.Initialize();

        }

    }

}
